var _that;
var _addCarCallBack, _buyCallBack;
// 添加购物车回调  立即购买回调
function init(target, addCarCallBack, buyCallBack) {
  _that = target,
    _addCarCallBack = addCarCallBack;
  _buyCallBack = buyCallBack;

  _that.setData({
    showbuy: false
  });
}

function showBuyDetail(goods) {
  //cakebuytop
  goods = {
    goodsid: 122,
    name: '鲜莓印雪',
    icon: '../imgs/cake/cake2.jpg',
    spec: [
      {
        specid: '12',
        value: '1磅',
        price: '198.00',
        tips1: '8',
        tips2: '2-3',
        size: '14cm * 7.0cm'
      },
      {
        specid: '13',
        value: '2磅',
        price: '298.00',
        tips1: '8',
        tips2: '4-7',
        size: '19cm * 7.0cm'
      },
      {
        specid: '14',
        value: '3磅',
        price: '428.00',
        tips1: '8',
        tips2: '8-12',
        size: '24cm * 7.0cm'
      },
      {
        specid: '15',
        value: '5磅',
        price: '728.00',
        tips1: '8',
        tips2: '12-20',
        size: '29cm * 7.0cm'
      }
    ]
  };
  var win_hgt = wx.getSystemInfoSync().windowHeight;
  _that.setData({
    cakebuytop: win_hgt,
    showbuy: true,
    curspec: 0,
    goods: goods
  });

  _that.animation.top(30).step();
  _that.setData({
    ckb_amt: _that.animation.export()
  });
  //ckb_amt
}

function closeBuyDetail() {
  _that.setData({
    showbuy: false
  });
}

function addCar() {
  _that.setData({
    showbuy: false
  });
  _addCarCallBack();
}

function buy() {
  _buyCallBack();
}

function chooseSpec(e) {
  var specid = e.currentTarget.dataset.specid;
  var goods = _that.data.goods;
  var curspec;
  for (var i = 0; i < goods.spec.length; i++) {
    if (goods.spec[i].specid == specid) {
      curspec = i;
      break;
    }
  }
  _that.setData({
    curspec: curspec
  });
}

module.exports = {
  init: init,
  show: showBuyDetail,
  close: closeBuyDetail,
  addCar: addCar,
  buy: buy,
  chooseSpec: chooseSpec
}





